package com.minio.miniospringboot.service;

/**
 * @ClassName: MinioService
 * @Desc: TODO
 * @auther: <Bang>
 * @Date: 2023/03/15 17:52
 * @Version: 1.0
 * @Modified By:
 */

import com.minio.miniospringboot.entity.UploadResult;
import io.minio.GetObjectResponse;
import io.minio.ObjectWriteResponse;
import io.minio.Result;
import io.minio.StatObjectResponse;
import io.minio.errors.*;
import io.minio.messages.Item;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public interface MinioService {


    /**
     * 获取bucket列表
     * @return
     */
    Iterable<Result<Item>> listObjects();


    StatObjectResponse statObject(String fileName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException;
    /**
     * 上传文件
     */
    UploadResult upload(MultipartFile multipartFile, boolean rename);

    /**
     * 复制文件
     *
     * @param source
     * @param target
     */
    ObjectWriteResponse copy(String source, String target);

    /**
     * 删除文件
     */
    void delete(String fileName);

    /**
     * 获取文件url预览
     */
    String getFileUrl(String objectName);

    /**
     * 获取文件流
     */
    GetObjectResponse getFile(String objectName) throws IOException;

    /**
     * 创建bucket
     *
     * @param bucketName
     * @return
     */
    boolean createBucketIfNotExists(String bucketName);

    /**
     * 设置bucket访问策略
     *
     * @return
     */
    void setBucketPolicy(String bucketName, String config);
}
